package com.example.a_java.controller;

import com.example.a_java.dto.PageResult;
import com.example.a_java.dto.ProductQuery;
import com.example.a_java.dto.RestResponse;
import com.example.a_java.entity.Product;
import com.example.a_java.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 产品管理控制�?
 */
@RestController
@RequestMapping("/product")
@RequiredArgsConstructor
public class ProductController {

    private final ProductService productService;

    /**
     * 获取产品列表
     */
    @GetMapping("/list")
    public RestResponse<PageResult<Product>> list(ProductQuery query) {
        return RestResponse.success(productService.getProductList(query));
    }

    /**
     * 获取产品详情
     */
    @GetMapping("/{id}")
    public RestResponse<Product> getProduct(@PathVariable Long id) {
        return RestResponse.success(productService.getProductById(id));
    }

    /**
     * 新增产品
     */
    @PostMapping
    public RestResponse<Long> add(@RequestBody Product product) {
        return RestResponse.success(productService.addProduct(product));
    }

    /**
     * 修改产品
     */
    @PutMapping
    public RestResponse<Void> update(@RequestBody Product product) {
        productService.updateProduct(product);
        return RestResponse.success();
    }

    /**
     * 删除产品
     */
    @DeleteMapping("/{ids}")
    public RestResponse<Void> delete(@PathVariable String ids) {
        productService.deleteProducts(ids);
        return RestResponse.success();
    }

    /**
     * 更新产品状�?
     */
    @PutMapping("/status")
    public RestResponse<Void> updateStatus(@RequestBody Product product) {
        productService.updateProductStatus(product);
        return RestResponse.success();
    }
} 
